import { Statement, STATEMENT_KIND, STATEMENT_TAG } from '../statement';
import { CreateBehavior } from './types';

export class CreateDatabase extends Statement {
  $kind: STATEMENT_KIND.CREATE_DATABASE = STATEMENT_KIND.CREATE_DATABASE;
  $name: string;
  $collate?: string;
  $tag: STATEMENT_TAG.EXECUTABLE = STATEMENT_TAG.EXECUTABLE;
  $behavior?: CreateBehavior;

  static isCreateDatabase(object: any): object is CreateDatabase {
    return (
      Statement.isStatement(object) &&
      object.$kind === STATEMENT_KIND.CREATE_DATABASE
    );
  }

  constructor(name: string) {
    super();
    this.$name = name;
  }

  collate(collate: string) {
    this.$collate = collate;
  }
}


export const CreateDatabaseBuilder = (name: string): CreateDatabase => {
  return new CreateDatabase(name);
};

CreateDatabaseBuilder.ifNotExists = function (name: string): CreateDatabase {
  const statement = CreateDatabaseBuilder(name);
  statement.$behavior = 'CREATE_IF_NOT_EXISTS';
  return statement;
};

// CreateDatabaseBuilder.orReplace = function (name: string): CreateDatabase {
//   const statement = CreateDatabaseBuilder(name);
//   statement.$behavior = 'CREATE_OR_REPLACE';
//   return statement;
// };

export type CreateDatabaseBuilder = typeof CreateDatabaseBuilder;
